//
//  LFFreshOrderTableViewCell.m
//  newload
//
//  Created by xue-iOS-work on 16/9/24.
//  Copyright © 2016年 xue. All rights reserved.
//

#import "LFFreshOrderTableViewCell.h"
#import "LFFreshOrderCollectionViewCell.h"
// 唯一标识
static NSString *collectionCellid = @"collectionCellid";

@interface LFFreshOrderTableViewCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property(nonatomic,strong)NSArray *goodsArray;

@end

@implementation LFFreshOrderTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self setupUI];
}
-(void)setModels:(LFFreshOrderActRowModel *)models
{
    _models = models;
    // 获取全局的数组
    NSArray *goodsArray =  self.models.activ_detail.goods;
    self.goodsArray = goodsArray;
    [self.collectionView reloadData];
    
}
// 初始化UI界面
-(void)setupUI{
    self.imageview.frame = CGRectMake(0, 0, 400, 80);
    // 注册
    [self.collectionView registerNib:[UINib nibWithNibName:@"LFFreshOrderCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:collectionCellid];
    // 设置数据源
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
}
#pragma mark - 数据源
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 7;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LFFreshOrderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionCellid forIndexPath:indexPath];
    //取到商品数组模型
    LFFreshOrdergoodsModel * model = self.goodsArray[indexPath.row];

    cell.model = model;
    //判断价钱一样的话 隐藏原价
    if([model.market_price isEqualToString:model.partner_price]){
//        cell.YuanPrice.hidden = YES;
        cell.YuanPrice.alpha = 0;
    }else
    {
//        cell.YuanPrice.hidden = NO;
        cell.YuanPrice.alpha = 1;
    }
    if (indexPath.row==6) {
        [cell.iconName mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(cell).offset(10);
            make.bottom.mas_equalTo(cell).offset(-10);
            make.left.mas_equalTo(cell).offset(18);
            make.right.mas_equalTo(cell).offset(-18);
        }];
        cell.titleName.hidden = YES;
        cell.YuanPrice.hidden = YES;
        cell.nowPrice.hidden = YES;
        cell.increateButton.hidden = YES;
        cell.descLabel.hidden = YES;
    }else
    {
        [cell.iconName mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(cell);
            make.left.mas_equalTo(cell).offset(8);
            make.right.mas_equalTo(cell).offset(8);
            make.height.offset(100);
        }];
        cell.titleName.hidden = NO;
        cell.YuanPrice.hidden = NO;
        cell.nowPrice.hidden = NO;
        cell.increateButton.hidden = NO;
        cell.descLabel.hidden = NO;
    }
    return cell;
    
}
#pragma mark - collectionView代理
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.myBlock) {
        LFFreshOrdergoodsModel *model = self.goodsArray[indexPath.row];
        self.myBlock(model);
        
    }
    
}

@end
